import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.NDC;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class HelloWorld extends AbstractHandler {
	
	static Logger logger = LoggerFactory.getLogger(HelloWorld.class.getClass());
	
	@Override
	public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
			throws IOException, ServletException {
		// 声明response的编码和文件类型
		response.setContentType("text/html; charset=utf-8");
		NDC.push("id??????id");
		// 声明返回状态码
		response.setStatus(HttpServletResponse.SC_OK);

		// 请求的返回值
		response.getWriter().println("<h1>Hello World</h1>");
		logger.info("hello ndc");
		// 通知Jettyrequest使用此处理器处理请求
		baseRequest.setHandled(true);
	}

	public static void main(String[] args) throws Exception {
		// 创建一个应用服务监听8080端口
		Server server = new Server(8080);
		server.setHandler(new HelloWorld());
		// 启动应用服务并等待请求
		server.start();
		server.join();
	}
}